# coding=utf-8
import getopt
import uuid

import oss2
import sys

import requests

AccessKeyId = 'LTAIv4prXZw4ElHB'
AccessKeySecret = 'POaKwz4kFzpFxfnfbBbU2xAILJ8APg'
Endpoint = 'oss-cn-beijing.aliyuncs.com'
Bucket = 'worldcuptemp'

auth = oss2.Auth(AccessKeyId, AccessKeySecret)
bucket = oss2.Bucket(auth, Endpoint, Bucket)

opts, args = getopt.getopt(sys.argv[1:], "", ["image="])
for op, value in opts:
    if op == "--image":
        image_url = value
if image_url == "" or image_url is None:
    print "url 为空"
    sys.exit()

input = requests.get(image_url)
if input.status_code != 200:
    print("图片下载失败")
    sys.exit()
name = "article/" + str(uuid.uuid1()) + ".jpg"
result = bucket.put_object(name, input)
if result.status != 200:
    print("图片上传失败")
    sys.exit()
print "https://worldcuptemp.oss-cn-beijing.aliyuncs.com/" + name
